<?php
require_once("./DButil.php");
header("Content-Type:application/json;charset=utf-8");

$arr=$_SESSION["loginTeacher"];


$roleId=$_REQUEST["role"];
$teacherId=$_REQUEST["id"];
$teacherName=$_REQUEST["name"];
$username=$_REQUEST["username"];


if ($arr["roleId"] > $roleId) {
    $result = [
        "msg" => "权限不够，禁止修改",
        "code" => 400,
        "success" => false
    ];
    echo json_encode($result);
    return;
}


$sql="select * from t_teacher where username='{$username}'";
$result1=query($sql);
$num=$result1[0]["teacherId"];
// echo json_encode($num);

if($num!=$teacherId){
    $result = [
        "msg" => "修改失败，用户名重复",
        "code" => 400,
        "success" => false
    ];
}else{
    $sql1="update t_teacher set teacherName='{$teacherName}',username='{$username}',roleId='{$roleId}' where teacherId='{$teacherId}'";
    $add=update($sql1);

    // echo json_encode($roleId);
    
    if ($add) {
        $result = [
            "msg" => "修改成功",
            "code" => 200,
            "success" => true
        ];
    }else{
        $result = [
            "msg" => "更新失败",
            "code" => 400,
            "success" => false
        ];
    }
}


echo json_encode($result);

?>